package com.xbongbong.saas.help.workflow;

import com.xbongbong.paas.domain.entity.PaasFormDataEntity;
import com.xbongbong.paas.elasticsearch.util.EsHelper;
import com.xbongbong.paas.elasticsearch.util.XbbElasticsearchRestTemplate;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.service.market.statistics.Contract4StaticHandle;
import com.xbongbong.pro.service.market.statistics.Customer4StaticHandle;
import com.xbongbong.pro.service.market.statistics.MarketActivity4StaticHandle;
import com.xbongbong.pro.service.market.statistics.factory.MarketActivity4StaticFactory;
import com.xbongbong.saas.domain.entity.StaticForMarketActivityEntity;
import com.xbongbong.saas.domain.entity.StaticForUpdateDTO;
import com.xbongbong.saas.domain.entity.StaticMarketForCustomerMergeEntity;
import com.xbongbong.saas.enums.RedundantTemplateTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.model.IndexTypeModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * date: 2022/3/14 9:29 上午
 *
 * @author yingjf
 * 下面加上MarketActivityEffectService市场活动成效查询的就是 市场活动中间统计表的所有操作入口
 */
@Component
@Slf4j
public class MarketActivityForStaticHelp {

    @Resource
    private MarketActivity4StaticFactory marketActivity4StaticFactory;
    @Resource
    private Customer4StaticHandle customer4StaticHandle;
    @Resource
    private Contract4StaticHandle contract4StaticHandle;
    @Resource
    private EsHelper esHelper;
    @Resource
    private IndexTypeModel indexTypeModel;

    /**
     * 新增市场活动
     *
     * @param paasFormDataEntity
     * @throws XbbException
     */
    public void addMarketActivity(PaasFormDataEntity paasFormDataEntity, XbbRefTypeEnum xbbRefTypeEnum) throws XbbException {
        MarketActivity4StaticHandle marketActivity4StaticHandle = marketActivity4StaticFactory.getMarketActivity4StaticHandle(xbbRefTypeEnum.getCode());
        marketActivity4StaticHandle.add(paasFormDataEntity);
    }

    /**
     * 更新数据同时更新中间表
     * date: 2022/3/14 9:46 上午
     *
     * @param paasFormDataEntity:
     * @param redundantTemplateTypeEnum:
     * @author yingjf
     */
    public void updateMarketActivity(PaasFormDataEntity paasFormDataEntity, RedundantTemplateTypeEnum redundantTemplateTypeEnum) throws XbbException {
        MarketActivity4StaticHandle marketActivity4StaticHandle = marketActivity4StaticFactory.getMarketActivity4StaticHandle(redundantTemplateTypeEnum.getCode());
        marketActivity4StaticHandle.update(paasFormDataEntity);
    }

    /**
     * 批量更新
     * date: 2022/3/15 4:20 下午
     *
     * @param list:
     * @param xbbRefTypeEnum:
     * @param corpid:
     * @author yingjf
     */
    public void updateBatchMarketActivity(List<StaticForUpdateDTO> list, XbbRefTypeEnum xbbRefTypeEnum, String corpid) throws XbbException {
        MarketActivity4StaticHandle marketActivity4StaticHandle = marketActivity4StaticFactory.getMarketActivity4StaticHandle(xbbRefTypeEnum.getCode());
        marketActivity4StaticHandle.updateBatch(list, corpid);
    }

    /**
     * 批量删除
     * date: 2022/3/15 4:20 下午
     *
     * @param idIn:
     * @param xbbRefTypeEnum:
     * @param corpid:
     * @param del:
     * @author yingjf
     */
    public void deleteBatchMarketActivity(List<Long> idIn, XbbRefTypeEnum xbbRefTypeEnum, String corpid, Integer del) throws XbbException {
        MarketActivity4StaticHandle marketActivity4StaticHandle = marketActivity4StaticFactory.getMarketActivity4StaticHandle(xbbRefTypeEnum.getCode());
        marketActivity4StaticHandle.deleteBatch(idIn, corpid, del);
    }

    /**
     * 客户合并
     * date: 2022/3/15 4:49 下午
     *
     * @param staticMarketForCustomerMergeEntity:
     * @author yingjf
     */
    public void deal2customerMerge(StaticMarketForCustomerMergeEntity staticMarketForCustomerMergeEntity) throws XbbException {
        customer4StaticHandle.customerMerge(staticMarketForCustomerMergeEntity);
    }

    public void addBatchContractByScript(String corpid, List<PaasFormDataEntity> list,List<StaticForMarketActivityEntity> StaticForMarketActivityList) throws XbbException {
        contract4StaticHandle.addBatchContractByScript(corpid, list,StaticForMarketActivityList);
    }
}
